package com.ktwlrj.autotask.service.impl;

import com.ktwlrj.autotask.model.dto.FundInfoDto;
import com.ktwlrj.autotask.model.dto.FundResult;
import com.ktwlrj.autotask.model.dto.FundResultInfoDto;
import com.ktwlrj.autotask.service.FundService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

/**
 * @author yuxf
 * @version 1.0
 * @date 2021/4/26 12:01
 */
@Service
@Slf4j
public class FundServiceImpl implements FundService {


    RestTemplate restTemplate = new RestTemplate();

    @Override
    public void sendSmsMessage() {

        //获取数据
        FundResultInfoDto fundInfo = getFundInfo();
        if(fundInfo.getCode().equals(200))
        {
            for (FundInfoDto fund : fundInfo.getData()) {
                log.info("{}({}) 估算涨幅：{},估算时间：{}",fund.getName(),fund.getCode(),fund.getExpectGrowth(),fund.getExpectWorthDate());
            }
        }

        //发送短信
    }

    /**
     * 获取基金信息
     */
    public FundResultInfoDto getFundInfo() {
        FundResultInfoDto forObject = restTemplate.getForObject("https://api.doctorxiong.club/v1/fund?code=320007&code=002586", FundResultInfoDto.class);
        return forObject;
    }


}
